#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
using namespace std;


struct TreeNode {
    int val;
    TreeNode* left;
    TreeNode* right;
    TreeNode() : val(0), left(nullptr), right(nullptr) {}
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
    TreeNode(int x, TreeNode* left, TreeNode* right) : val(x), left(left), right(right) {}
};

int countNodes(TreeNode* root) {
    if (root == nullptr)
        return 0;
    return 1 + countNodes(root->left) + countNodes(root->right);
}

bool isSameTree(TreeNode* p, TreeNode* q) {
    if (p == nullptr && q == nullptr)
        return true;
    if (p == nullptr || q == nullptr)
        return false;

    if (p->val != q->val)
        return false;

    return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}

bool isUnivalTree(TreeNode* root) {
    if (root == nullptr)
        return true;

    if (root->left && root->val != root->left->val)
        return false;

    if (root->right && root->val != root->right->val)
        return false;

    return isUnivalTree(root->left)
        && isUnivalTree(root->right);
}

bool  _isSymmetric(TreeNode* left, TreeNode* right)
{
    if (left == nullptr && right == nullptr)
        return true;

    if (left == nullptr || right == nullptr)
        return false;

    if (left->val != right->val)
        return false;

    return _isSymmetric(left->left, right->right)
        && _isSymmetric(left->right, right->left);
}

bool isSymmetric(TreeNode* root) {
    if (root == nullptr)
        return true;

    return _isSymmetric(root->left, root->right);
}

struct TreeNode
{
    char val;
    TreeNode* left;
    TreeNode* right;

    TreeNode(char ch)
        :val(ch)
        , left(nullptr)
        , right(nullptr)
    {}
};

TreeNode* creatTree(string& str, int& i)
{
    if (str[i] == '#')
    {
        i++;
        return nullptr;
    }

    auto node = new TreeNode(str[i++]);
    node->left = creatTree(str, i);
    node->right = creatTree(str, i);
    return node;
}

void InOrder(TreeNode* root)
{
    if (root == nullptr)
        return;

    InOrder(root->left);
    cout << root->val << " ";
    InOrder(root->right);
}

int main() {
    string str;
    cin >> str;
    int i = 0;
    TreeNode* root = creatTree(str, i);
    InOrder(root);
    return 0;
}

TreeNode* invertTree(TreeNode* root) {
    if (root == nullptr)
        return nullptr;

    TreeNode* tmp = root->left;
    root->left = root->right;
    root->right = tmp;

    invertTree(root->left);
    invertTree(root->right);

    return root;
}

//bool isSameTree(TreeNode* p, TreeNode* q)
//{
//    if (p == nullptr && q == nullptr)
//        return true;
//
//    if (p == nullptr || q == nullptr)
//        return false;
//
//    if (p->val != q->val)
//        return false;
//
//    return isSameTree(p->left, q->left)
//        && isSameTree(p->right, q->right);
//}

bool isSubtree(TreeNode* root, TreeNode* subRoot) {
    if (root == nullptr && subRoot == nullptr)
        return true;

    if (root == nullptr || subRoot == nullptr)
        return false;

    if (root->val == subRoot->val && isSameTree(root, subRoot))
        return true;

    return isSubtree(root->left, subRoot)
        || isSubtree(root->right, subRoot);
}


//string tree2str(TreeNode* root) {
//
//    if (root == nullptr)
//        return "";
//
//    if (root->left == nullptr && root->right == nullptr)
//        return to_string(root->val);
//
//    if (root->right == nullptr)
//        return to_string(root->val) + "(" + tree2str(root->left) + ")";
//
//    return to_string(root->val)
//        + "(" + tree2str(root->left) + ")"
//        + "(" + tree2str(root->right) + ")";
//}

#include<vector>
#include<queue>
vector<vector<int>> levelOrder(TreeNode* root)
{
    vector<vector<int>> ret;
    if (root == nullptr)
        return ret;
    queue<TreeNode*> q;
    q.push(root);
    while (!q.empty())
    {
        int n = q.size();
        vector<int> tmp;
        while (n--)
        {
            TreeNode* front = q.front();
            q.pop();
            tmp.push_back(front->val);
            if (front->left)
                q.push(front->left);
            if (front->right)
                q.push(front->right);
        }
        ret.push_back(tmp);
    }
    return ret;
}